package org.zachary.commonservice.service.impl;

import org.springframework.stereotype.Service;
import org.zachary.commonmodule.entity.MqTransmissionJson;
import org.zachary.commonservice.entity.OverdueRecord;
import org.zachary.commonservice.mapper.OverdueMapper;
import org.zachary.commonservice.service.OverdueService;

@Service
public class OverdueServiceImpl implements OverdueService {
    private final OverdueMapper overdueMapper;

    public OverdueServiceImpl(OverdueMapper overdueMapper) {
        this.overdueMapper = overdueMapper;
    }

    @Override
    public void storeOverdueRecord(OverdueRecord overdueRecord) {
        overdueMapper.storeOverdueRecord(overdueRecord);
    }

    @Override
    public OverdueRecord getOverdueRecord(String uuid) {
        return overdueMapper.findByUuid(uuid);
    }

    @Override
    public void setFinished(OverdueRecord json) {
        OverdueRecord overdueRecord = overdueMapper.findByUuid(json.getUuid());
        if(overdueRecord == null) {
            throw new RuntimeException("该条逾期记录不存在，请检查后重试");
        }

        overdueMapper.setFinished(json);
    }
}
